import QtQuick 1.1
import com.nokia.meego 1.1

Page {

    property bool empty: accountList.count <= 1

    tools: commonTools

    function del()
    {
        console.log("Deleting Account")
    }
    function edit()
    {
        console.log("Editing Account")
        appWindow.pageStack.push(Qt.resolvedUrl("AccountEdit.qml"), {
                                                                    name: accountList.currentItem.name,
                                                                    persons: accountList.currentItem.persons,
                                                                    acnt_id: Number(accountList.currentIndex),
                                                                    edit: true})
    }
    function add()
    {
        console.log("adding new Account")
        appWindow.pageStack.push(Qt.resolvedUrl("AccountEdit.qml"), {
                                                                    name: "",
                                                                    persons: "1",
                                                                    acnt_id: accountList.count,
                                                                    edit: false})
    }

    VisualDataModel {
        id: accountModel

        model: myAccounts
    
        Component {
            id: accountDelegate
            Item {
                property variant name: model.name
                property variant persons: model.parties
                width: parent.width
                height:child.height*1.4 
                anchors{leftMargin: 10; left:parent.left}
                Row {
                    width: parent.width
                    id:child
                    spacing: 5
                    anchors.verticalCenter: parent.verticalCenter
                    Label {
                        text: name; color: 'green'; font.pixelSize: 40;
                    }
                    Label {
                        text: ': #' + persons + ' persons';
                        color: 'purple'; font.pixelSize: 40;
                    }
                }
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        accountList.currentIndex = index
                    }
                }
            }
        }
    }
    ListView {
        id: accountList
        anchors.fill: parent
        model: accountModel
        highlight: Rectangle{width:parent.width; smooth:true; opacity:0.5; color: "darkslategrey"; radius: 10}
        focus: true
        spacing: 5
    }


}
